package com.wufan.day07.java;

import java.util.Scanner;

/**
 * @author SongWufan
 * @date 2021/6/1 13:59
 */
public class AngleTest {
    /**
     * 判断是否能构成三角形
     *
     * @param a
     * @param b
     * @param c
     * @return
     */
    public static double judgeAngle(double a, double b, double c) {
        if (a + b > c && a + c > b && b + c > a) {
            return 1;
        }
        System.out.println("不能构成三角形");
        System.exit(-1);
        return 0;
    }

    /**
     * 判断是否为等腰或等边三角形
     *
     * @param a
     * @param b
     * @param c
     * @return
     */
    public static double judgeDangle(double a, double b, double c) {
        if (a == b || a == c || b == c) {
            if (a == b && a == c) {
                System.out.println("等边三角形");
            } else {
                System.out.println("等腰三角形");
            }
            System.exit(-1);
            return 1;
        }
        return 0;
    }

    /**
     * 主程序
     *
     * @param args
     */
    public static void main(String[] args) {
        double a, b, c;
        System.out.println("请输入三角形的三条边，输入0退出");
        double[] doubleArray = new double[4];
        double j;
        try {
            Scanner sc = new Scanner(System.in);
            for (int i = 1; i < 4; i++) {
                System.out.println("请输入第" + i + "条边：");
                j = sc.nextDouble();
                    doubleArray[i] = j;
            }
            sc.close();
        } catch (Exception e) {
            System.out.println("只能输入数字");
        }

        a = doubleArray[1];
        b = doubleArray[2];
        c = doubleArray[3];

        //判断输入三边是否合法
        if (a <= 0 || b <= 0 || c <= 0) {
            System.out.println("输入的三边不合法");
        } else {
            //判断是否构成三角形
            judgeAngle(a, b, c);
            //判断是否是等腰或等边三角形
            judgeDangle(a, b, c);
            //判断是否为一般三角形
            System.out.println("普通三角形");
        }
    }
}
